<template>
  <el-dialog
    title="新增目录"
    :visible="showDialog"
    style="width: 70%"
    @close="btnCancel"
  >
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="addContent"
      label-width="100px"
    >
      <el-form-item label="所属学科" prop="region">
        <el-select
          v-model="ruleForm.region"
          placeholder="请选择"
          style="width: 100%"
        >
        </el-select>
      </el-form-item>
      <el-form-item label="目录名称" prop="name">
        <el-input
          v-model="ruleForm.name"
          placeholder="请输入目录名称"
        ></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="btnCancel">取消</el-button>
      <el-button type="primary" @click="btnOK">确定</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  props: {
    showDialog: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      ruleForm: {
        region: '', // 所属学科
        name: '' // 目录名称
      },
      rules: {
        region: [{ required: true, message: '请选择学科', trigger: 'blur' }],
        name: [{ required: true, message: '请输入标签名称', trigger: 'blur' }]
      }
    }
  },
  methods: {
    // 添加标签
    async btnOK () {
      // 1.手动校验表单
      // await this.$refs.addContent.validate()
      // 2.调用接口
      // 3.关闭弹窗
      // 4.视图同步
      // 5.提示信息
    },
    // 取消添加
    btnCancel () {
      // 1.数据初始化
      this.ruleForm = {
        name: '',
        region: ''
      }
      // 2.校验初始化
      // this.$refs.addContent.resetFields()
      // 3.关闭弹层
      this.$emit('update:showDialog', false)
    }
  }
}
</script>

<style scoped lang='less'></style>
